package com.example.admin.yuejian21.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.admin.yuejian21.Bean.Club;
import com.example.admin.yuejian21.Bean.Pic;
import com.example.admin.yuejian21.Bean.shaier;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.ViewHolder.PicViewHolder;
import com.example.admin.yuejian21.ViewHolder.renqiViewHolder;
import com.example.admin.yuejian21.activity.ClubDetailActivity;
import com.example.admin.yuejian21.activity.PicDetailActivity;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

import static com.example.admin.yuejian21.activity.LoginActivity.username;

/**
 * Created by Admin on 2017/10/23.
 */

public class PicAdapter extends RecyclerView.Adapter {
    private List<Pic> PicList =new ArrayList<>();

    private Context context;
    private LayoutInflater layoutInflater;
    public  static String picid;
    public static String usernamest;
    public   static Object photo1;
    public static String picuserid;
    public PicAdapter(Context context,List<Pic> Piclist ) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.PicList.addAll(Piclist);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView =
                layoutInflater.inflate(R.layout.item_pic,parent,false);

        PicViewHolder holder =
                new PicViewHolder(itemView);

        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        PicViewHolder picViewHolder =
                (PicViewHolder) holder;
        final Pic pic= PicList.get(position);

      final shaier shaier =pic.getShaier();
        if(null!=shaier) {final String username1=shaier.getUser_name();picViewHolder.usernameView.setText(username1);}
        else {picViewHolder.usernameView.setText(username);}
        String hit =pic.getHits();






        picViewHolder.hitView.setText(hit);



        if(null!=shaier)
        { if (PicList.get(position).getShaier().getPhoto()!=null) {
     Picasso
             .with(context)
             .load("http://172.24.10.175/workout/Uploads/" + PicList.get(position).getShaier().getPhoto())


             .into(
                     picViewHolder.userView);
 }}
     if(PicList.get(position).getThumb0()!=null){
        Picasso
                .with(context)
                .load("http://172.24.10.175/workout/Uploads/"+PicList.get(position).getThumb0())


                .into(
                        picViewHolder.pic);}
       picViewHolder.itemview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, PicDetailActivity.class);

                intent.putExtra("pic",pic);
                picid = pic.getId();
            if(null!=shaier) {  usernamest=pic.getShaier().getUser_name();
             photo1=pic.getShaier().getPhoto();}
                context.startActivity(intent);
                picuserid=pic.getUserid();


            }
        });

    }

    @Override
    public int getItemCount() {
        return PicList.size();
    }
}
